//
//  storeTip.swift
//  uiKit-demo
//
//  Created by 陈澎 on 2025/1/17.
//

import UIKit
class StoreTipViewController {
    var title: String = "11111111"

    func render(parentView: UIView) -> UIView {
        // 可适用门店信息提醒
        let storeInfoView = UIView()
        storeInfoView.frame = CGRect(x: 0, y: 0, width: parentView.bounds.width, height: ScaleBasedScene.getFinalSizeVal(60))
        storeInfoView.backgroundColor = .green
//        storeInfoView.translatesAutoresizingMaskIntoConstraints = false
//        parentView.addSubview(storeInfoView)
        
        // 背景图
        let storeInfoBg = UIImageView()
        storeInfoBg.frame = CGRect(x: 0, y: 0, width: parentView.bounds.width, height: ScaleBasedScene.getFinalSizeVal(60))
        storeInfoBg.image = UIImage(named: "storeInfoBg")
        storeInfoBg.contentMode = .scaleAspectFill
//        storeInfoBg.translatesAutoresizingMaskIntoConstraints = false
        storeInfoView.addSubview(storeInfoBg)
 
        // 内容容器
        let gradientView = UIView()
        gradientView.translatesAutoresizingMaskIntoConstraints = false
        storeInfoView.addSubview(gradientView)
        
        // 内容
        let infoLabel = UILabel()
        infoLabel.font = UIFont.systemFont(ofSize: 14, weight: .bold)
        infoLabel.textAlignment = .left
        infoLabel.numberOfLines = 2
        infoLabel.textColor = UIColor(red: 0.99, green: 0.45, blue: 0.01, alpha: 1)
        infoLabel.translatesAutoresizingMaskIntoConstraints = false
        
        // 设置行高
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 6 // 设置行间距
        let attributedString = NSAttributedString(
            string: self.title,
            attributes: [
                .paragraphStyle: paragraphStyle
            ]
        )
        infoLabel.attributedText = attributedString
        
        gradientView.addSubview(infoLabel)
        
        NSLayoutConstraint.activate([
//            storeInfoView.topAnchor.constraint(equalTo: parentView.topAnchor),
//            storeInfoView.leadingAnchor.constraint(equalTo: parentView.leadingAnchor),
//            storeInfoView.trailingAnchor.constraint(equalTo: parentView.trailingAnchor),
//            storeInfoView.heightAnchor.constraint(equalToConstant: 60),
            
//            storeInfoBg.topAnchor.constraint(equalTo: storeInfoView.topAnchor),
//            storeInfoBg.leadingAnchor.constraint(equalTo: storeInfoView.leadingAnchor),
//            storeInfoBg.trailingAnchor.constraint(equalTo: storeInfoView.trailingAnchor),
//            storeInfoBg.bottomAnchor.constraint(equalTo: storeInfoView.bottomAnchor),
            
            gradientView.topAnchor.constraint(equalTo: storeInfoView.topAnchor, constant: 9.5),
            gradientView.bottomAnchor.constraint(equalTo: storeInfoView.bottomAnchor, constant: 10.5),
            gradientView.leadingAnchor.constraint(equalTo: storeInfoView.leadingAnchor, constant: 12),
            gradientView.trailingAnchor.constraint(equalTo: storeInfoView.trailingAnchor, constant: -12),
            
            infoLabel.leadingAnchor.constraint(equalTo: gradientView.leadingAnchor, constant: 12),
            infoLabel.trailingAnchor.constraint(equalTo: gradientView.trailingAnchor, constant: -12),
//            infoLabel.centerXAnchor.constraint(equalTo: gradientView.centerXAnchor),
//            infoLabel.centerYAnchor.constraint(equalTo: gradientView.centerYAnchor)
        ])
        return storeInfoView
    }
}
